#ifndef CHEETAH_GRAPHICS_RENDER_DEVICE_H
#define CHEETAH_GRAPHICS_RENDER_DEVICE_H

#include "cheetah/core/settings.h"
#include <GL/glew.h>

#include "cheetah/graphics/framebuffer_object.h"

namespace cheetah {
namespace graphics {
class Texture2D;
class RenderBuffer;
class RenderDeviceFBO {
 public:
  void Activate() { fbo_.Bind(); }
  void Deactivate() { FramebufferObject::Disable(); }
  void Check() { fbo_.IsValid(); }
  void SetRenderTarget(const Texture2D *texture);
  void SetRenderTargets(int target_counts, 
                        const Texture2D *const textures[]);
  void SetRenderTarget(const RenderBuffer *render_buffer);
  void SetRenderTargets(int target_counts, 
                        const RenderBuffer *const render_buffers[]);
  void SetDepthBuffer(const Texture2D *texture);
  void SetDepthBuffer(const RenderBuffer *render_buffer);
  void DisableDepthBuffer();
  template<typename T>
  void AdjustViewport(const T *target) {
    glViewport(0, 0, target->width(), target->height());
  }
  /*
   * there may be problem in the case of multiple render targets,
   * if simply disable frame buffer object, maybe here should record them
   * and detach them when necessary, for example, when target_count exceeds
   * the target_count in last call to SetRenderTargetGL
   */
  void SaveMVP();
  void RestoreMVP();
 private:
  FramebufferObject fbo_;
  static GLint s_viewport[4];
};
} // graphics
} // cheetah

#endif // CHEETAH_GRAPHICS_RENDER_DEVICE_H
